package servlet;

import dao.ScoreDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/add_score")
public class add_score extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");

        PrintWriter out = response.getWriter();

        ScoreDao scoreDao = new ScoreDao();

        String id = request.getParameter("id");
        String course_name = request.getParameter("course_name");
        String score = request.getParameter("score");
        String level = request.getParameter("level");
        String stu_id = request.getParameter("stu_id");

        try {
            scoreDao.insertScore(id,course_name, score, level,stu_id);
        }
        catch (Exception e){
            out.print(e);
        }
        response.sendRedirect("one_page_score");
    }
}
